########################################
# Passive effects events
#
# scripted by Ogulcan Yildirim
########################################

namespace = passive_effects_events
	
# Increase the opinion of all brothers of faith
country_event = {
	id = passive_effects_events.1
	title = none
	desc = none
	picture = none
	hidden = yes

	trigger = {
		has_country_flag = has_increased_religios_opinion
		any_known_country = {
			religion = ROOT
			NOT = {
				has_opinion_modifier = {
					who = ROOT
					modifier = increased_same_religion
				}
			}
		}
	}

	mean_time_to_happen = {
		days = 1
	}
	
	option = { 
		every_known_country = {
			limit = {
				religion = ROOT
				NOT = {
					has_opinion_modifier = {
						who = ROOT
						modifier = increased_same_religion
					}
				}
			}
			add_opinion = {
				who = ROOT
				modifier = increased_same_religion
			}
			reverse_add_opinion = {
				who = ROOT
				modifier = increased_same_religion
			}
		}
		
		ai_chance = {
			factor = 1
		}
	}
}
	
# Remove opinion if religion is incorrect
country_event = {
	id = passive_effects_events.2
	title = none
	desc = none
	picture = none
	hidden = yes

	trigger = {
		has_country_flag = has_increased_religios_opinion
		any_known_country = {
			NOT = { religion = ROOT }
			has_opinion_modifier = {
				who = ROOT
				modifier = increased_same_religion
			}
		}
	}

	mean_time_to_happen = {
		months = 1
	}
	
	option = { 
		every_known_country = {
			limit = {
				NOT = { religion = ROOT }
				has_opinion_modifier = {
					who = ROOT
					modifier = increased_same_religion
				}
			}
			remove_opinion = {
				who = ROOT
				modifier = increased_same_religion
			}
			reverse_remove_opinion = {
				who = ROOT
				modifier = increased_same_religion
			}
		}
		
		ai_chance = {
			factor = 1
		}
	}
}
	
# Increase the opinion of all Fetishists
country_event = {
	id = passive_effects_events.3
	title = none
	desc = none
	picture = none
	hidden = yes

	trigger = {
		has_country_flag = has_increased_fetishist_same_religion_opinion
		religion = shamanism
		any_known_country = {
			religion = shamanism
			NOT = {
				has_opinion_modifier = {
					who = ROOT
					modifier = increased_fetishist_opinion
				}
			}
		}
	}

	mean_time_to_happen = {
		days = 1
	}
	
	option = { 
		every_known_country = {
			limit = {
				religion = shamanism
				NOT = {
					has_opinion_modifier = {
						who = ROOT
						modifier = increased_fetishist_opinion
					}
				}
			}
			add_opinion = {
				who = ROOT
				modifier = increased_fetishist_opinion
			}
			reverse_add_opinion = {
				who = ROOT
				modifier = increased_fetishist_opinion
			}
		}
		
		ai_chance = {
			factor = 1
		}
	}
}
	
# Increase the opinion of all Christians / Muslims if picked the diplomatic rabbi aspect
country_event = {
	id = passive_effects_events.4
	title = none
	desc = none
	picture = none
	hidden = yes

	trigger = {
		has_church_aspect = judaism_diplomatic_rabbi_aspect
		any_known_country = {
			OR = {
				religion_group = muslim
				religion_group = christian
			}
			NOT = { government = theocracy }
			NOT = {
				has_opinion_modifier = {
					who = ROOT
					modifier = diplomatic_rabbi_opinion
				}
			}
		}
	}

	mean_time_to_happen = {
		days = 1
	}
	
	option = { 
		every_known_country = {
			limit = {
				OR = {
					religion_group = muslim
					religion_group = christian
				}
				NOT = { government = theocracy }
				NOT = {
					has_opinion_modifier = {
						who = ROOT
						modifier = diplomatic_rabbi_opinion
					}
				}
			}
			add_opinion = {
				who = ROOT
				modifier = diplomatic_rabbi_opinion
			}
			reverse_add_opinion = {
				who = ROOT
				modifier = diplomatic_rabbi_opinion
			}
		}
		
		ai_chance = {
			factor = 1
		}
	}
}
	
# Remove opinion when aspect gets removed
country_event = {
	id = passive_effects_events.5
	title = none
	desc = none
	picture = none
	hidden = yes

	trigger = {
		NOT = { has_church_aspect = judaism_diplomatic_rabbi_aspect }
		any_country = {
			has_opinion_modifier = {
				who = ROOT
				modifier = diplomatic_rabbi_opinion
			}
		}
	}

	mean_time_to_happen = {
		months = 1
	}
	
	option = { 
		every_country = {
			limit = {
				has_opinion_modifier = {
					who = ROOT
					modifier = diplomatic_rabbi_opinion
				}
			}
			remove_opinion = {
				who = ROOT
				modifier = diplomatic_rabbi_opinion
			}
			reverse_remove_opinion = {
				who = ROOT
				modifier = diplomatic_rabbi_opinion
			}
		}
		
		ai_chance = {
			factor = 1
		}
	}
}
	
# Remove temporary colonist when colonist idea is unlocked
country_event = {
	id = passive_effects_events.6
	title = none
	desc = none
	picture = none
	hidden = yes

	trigger = {
		has_country_modifier = temporary_colonist
		has_any_colonist_idea = yes
	}

	mean_time_to_happen = {
		months = 1
	}
	
	option = { 
		remove_country_modifier = temporary_colonist
		
		ai_chance = {
			factor = 1
		}
	}
}

# Add siege progress when retaking own fort
country_event = {
	id = passive_effects_events.7
	title = none
	desc = none
	picture = none
	hidden = yes

	trigger = {
		religion = jewish
		has_church_aspect = judaism_remember_passover_aspect
		any_owned_province = {
			NOT = { controlled_by = ROOT }
			OR = {
				has_building = fort_15th
				has_building = fort_16th
				has_building = fort_17th
				has_building = fort_18th
				is_capital = yes
				has_building = native_palisade
			}
			NOT = { has_province_flag = getting_retaken_by_owner }
			sieged_by = ROOT
		}
	}

	mean_time_to_happen = {
		days = 1
	}

	option = {
		every_owned_province = {
			limit = {
				NOT = { controlled_by = ROOT }
				OR = {
					has_building = fort_15th
					has_building = fort_16th
					has_building = fort_17th
					has_building = fort_18th
					is_capital = yes
					has_building = native_palisade
				}
				NOT = { has_province_flag = getting_retaken_by_owner }
				sieged_by = ROOT
			}
			change_siege = 2
			set_province_flag = getting_retaken_by_owner
		}

		ai_chance = {
			factor = 1
		}
	}
}

# Remove siege progress when aspect gets removed
country_event = {
	id = passive_effects_events.8
	title = none
	desc = none
	picture = none
	hidden = yes

	trigger = {
		any_owned_province = {
			has_province_flag = getting_retaken_by_owner
			OR = {
				owner = {
					OR = {
						NOT = { religion = jewish }
						NOT = { has_church_aspect = judaism_remember_passover_aspect }
					}
				}
				has_siege = no
			}
		}
	}

	mean_time_to_happen = {
		days = 1
	}

	option = {
		every_owned_province = {
			limit = {
				has_province_flag = getting_retaken_by_owner
				has_siege = no
			}
			clr_province_flag = getting_retaken_by_owner
		}

		ai_chance = {
			factor = 1
		}
	}
}

# Remove the unrest from seizure estate land
province_event = {
	id = passive_effects_events.9
	title = none
	desc = none
	picture = none
	hidden = yes

	trigger = {
		had_province_flag = {
			flag = has_estate_unrest_flag
			days = 3650
		}
	}

	mean_time_to_happen = {
		days = 5
	}

	option = {
		clr_province_flag = has_estate_unrest_flag
		remove_named_unrest = estate_land_seized

		ai_chance = {
			factor = 1
		}
	}
}
	
# Increase the opinion of all nations with a specified religion (gets called by add_opinion_of_religion)
country_event = {
	id = passive_effects_events.11
	title = none
	desc = none
	picture = none
	hidden = yes

	trigger = {
		has_country_flag = has_improve_opinion_flag
		any_known_country = {
			has_religion_of_increased_opinion_for_scope = {
				who = ROOT
			}
			NOT = {
				has_opinion_modifier = {
					who = ROOT
					modifier = increased_religion_opinion
				}
			}
		}
	}

	mean_time_to_happen = {
		months = 1
	}
	
	option = { 
		every_known_country = {
			limit = {
				has_religion_of_increased_opinion_for_scope = {
					who = ROOT
				}
				NOT = {
					has_opinion_modifier = {
						who = ROOT
						modifier = increased_religion_opinion
					}
				}
			}
			add_opinion = {
				who = ROOT
				modifier = increased_religion_opinion
			}
			reverse_add_opinion = {
				who = ROOT
				modifier = increased_religion_opinion
			}
		}
		
		ai_chance = {
			factor = 1
		}
	}
}

# Colony sends own missionary if "increase religious control" is active
country_event = {
	id = passive_effects_events.12
	title = none
	desc = none
	picture = none
	hidden = yes

	trigger = {
		has_country_flag = has_increased_religious_control
		any_owned_province = {
			NOT = { religion = ROOT }
			NOT = { has_province_modifier = religious_center }
			NOT = { has_province_modifier = judaism_abrahamic_roots }
			NOT = { has_province_modifier = religious_zeal_at_conv }
			NOT = { has_province_modifier = hun_reformed_colleges }
			NOT = { has_province_modifier = hun_military_frontier_modifier }
			NOT = { has_province_modifier = tatar_feudatory_province }
			NOT = { has_province_modifier = puritan_settlement }
			NOT = { has_province_modifier = estate_dhimmi_guaranteed_autonomy_mod }
			NOT = { has_province_modifier = estate_brahmins_guaranteed_autonomy_mod }
			NOT = { has_province_modifier = estate_church_lao_animism_mod }
		}
		all_owned_province = {	#Makes sure that the colony doesn't try to send two missionary
			has_missionary = no
		}
		has_global_modifier_value = {
			which = missionaries
			value = 1
		}
	}

	mean_time_to_happen = {
		months = 1
	}

	immediate = {		#The setting 
		random_owned_province = {	#Random province
			limit = {
				NOT = { religion = ROOT }
				NOT = { has_province_modifier = judaism_abrahamic_roots }
				NOT = { has_province_modifier = religious_zeal_at_conv }
				NOT = { has_province_modifier = hun_reformed_colleges }
				NOT = { has_province_modifier = hun_military_frontier_modifier }
				NOT = { has_province_modifier = tatar_feudatory_province }
				NOT = { has_province_modifier = puritan_settlement }
				NOT = { has_province_modifier = estate_dhimmi_guaranteed_autonomy_mod }
				NOT = { has_province_modifier = estate_brahmins_guaranteed_autonomy_mod }
				NOT = { has_province_modifier = estate_church_lao_animism_mod }
				has_missionary = no
			}
			save_event_target_as = converting_province
		}
		random_owned_province = {	#Not a religious center
			limit = {
				NOT = { religion = ROOT }
				NOT = { has_province_modifier = religious_center }
				NOT = { has_province_modifier = judaism_abrahamic_roots }
				NOT = { has_province_modifier = religious_zeal_at_conv }
				NOT = { has_province_modifier = hun_reformed_colleges }
				NOT = { has_province_modifier = hun_military_frontier_modifier }
				NOT = { has_province_modifier = tatar_feudatory_province }
				NOT = { has_province_modifier = puritan_settlement }
				NOT = { has_province_modifier = estate_dhimmi_guaranteed_autonomy_mod }
				NOT = { has_province_modifier = estate_brahmins_guaranteed_autonomy_mod }
				NOT = { has_province_modifier = estate_church_lao_animism_mod }
				has_missionary = no
			}
			save_event_target_as = converting_province
		}
		random_owned_province = {	#Not a religious center, has accepted culture or is culture group or is state
			limit = {
				NOT = { religion = ROOT }
				NOT = { has_province_modifier = religious_center }
				NOT = { has_province_modifier = judaism_abrahamic_roots }
				NOT = { has_province_modifier = religious_zeal_at_conv }
				NOT = { has_province_modifier = hun_reformed_colleges }
				NOT = { has_province_modifier = hun_military_frontier_modifier }
				NOT = { has_province_modifier = tatar_feudatory_province }
				NOT = { has_province_modifier = puritan_settlement }
				NOT = { has_province_modifier = estate_dhimmi_guaranteed_autonomy_mod }
				NOT = { has_province_modifier = estate_brahmins_guaranteed_autonomy_mod }
				NOT = { has_province_modifier = estate_church_lao_animism_mod }
				OR = {
					is_state = yes
					OR = {
						culture_group = ROOT
						has_owner_accepted_culture = yes
					}
				}
				has_missionary = no
			}
			save_event_target_as = converting_province
		}
		random_owned_province = {	#Not a religious center, has accepted culture or is culture group or is state or is low dev
			limit = {
				NOT = { religion = ROOT }
				NOT = { has_province_modifier = religious_center }
				NOT = { has_province_modifier = judaism_abrahamic_roots }
				NOT = { has_province_modifier = religious_zeal_at_conv }
				NOT = { has_province_modifier = hun_reformed_colleges }
				NOT = { has_province_modifier = hun_military_frontier_modifier }
				NOT = { has_province_modifier = tatar_feudatory_province }
				NOT = { has_province_modifier = puritan_settlement }
				NOT = { has_province_modifier = estate_dhimmi_guaranteed_autonomy_mod }
				NOT = { has_province_modifier = estate_brahmins_guaranteed_autonomy_mod }
				NOT = { has_province_modifier = estate_church_lao_animism_mod }
				OR = {
					is_state = yes
					OR = {
						culture_group = ROOT
						has_owner_accepted_culture = yes
					}
					NOT = { development = 10 }
				}
				has_missionary = no
			}
			save_event_target_as = converting_province
		}
		random_owned_province = {	#Not a religious center, has accepted culture or is culture group or is state, low dev
			limit = {
				NOT = { religion = ROOT }
				NOT = { has_province_modifier = religious_center }
				NOT = { has_province_modifier = judaism_abrahamic_roots }
				NOT = { has_province_modifier = religious_zeal_at_conv }
				NOT = { has_province_modifier = hun_reformed_colleges }
				NOT = { has_province_modifier = hun_military_frontier_modifier }
				NOT = { has_province_modifier = tatar_feudatory_province }
				NOT = { has_province_modifier = puritan_settlement }
				NOT = { has_province_modifier = estate_dhimmi_guaranteed_autonomy_mod }
				NOT = { has_province_modifier = estate_brahmins_guaranteed_autonomy_mod }
				NOT = { has_province_modifier = estate_church_lao_animism_mod }
				OR = {
					is_state = yes
					OR = {
						culture_group = ROOT
						has_owner_accepted_culture = yes
					}
				}
				NOT = { development = 10 }
				has_missionary = no
			}
			save_event_target_as = converting_province
		}
		random_owned_province = {	#Not a religious center, has accepted culture or is culture group, is state, low dev
			limit = {
				NOT = { religion = ROOT }
				NOT = { has_province_modifier = religious_center }
				NOT = { has_province_modifier = judaism_abrahamic_roots }
				NOT = { has_province_modifier = religious_zeal_at_conv }
				NOT = { has_province_modifier = hun_reformed_colleges }
				NOT = { has_province_modifier = hun_military_frontier_modifier }
				NOT = { has_province_modifier = tatar_feudatory_province }
				NOT = { has_province_modifier = puritan_settlement }
				NOT = { has_province_modifier = estate_dhimmi_guaranteed_autonomy_mod }
				NOT = { has_province_modifier = estate_brahmins_guaranteed_autonomy_mod }
				NOT = { has_province_modifier = estate_church_lao_animism_mod }
				is_state = yes
				OR = {
					culture_group = ROOT
					has_owner_accepted_culture = yes
				}
				NOT = { development = 10 }
				has_missionary = no
			}
			save_event_target_as = converting_province
		}
	}

	option = {
		event_target:converting_province = {
			send_missionary = yes
		}
		ai_chance = {
			factor = 1
		}
	}
}